1. Field of the Invention
The present invention relates generally to computer graphics shading and more specifically to omnidirectional shading using a shadow texture cube mapping.
2. Description of the Related Art
Real-time computer image systems are designed to provide realistic image reproduction for a wide variety of graphics systems, such as flight simulators, action games, and engineering workstations. For example, graphics-based simulators can be used as training devices, which permit combatants to obtain practice without the necessity of going out into the field and using the actual combat systems. The simulators enable a user, such as a pilot, to maintain and improve their skills without the cost associated with live training. As such, it is advantageous to provide the user with video display realism.
FIG. 1 is a diagram showing a three-dimensional (3D) viewing space 100. When creating three-dimensional computer generated graphics, 3D objects 104 are rendered from a camera's 102 point of view, generally between a near plane 106 and a far plane 108. In addition, a light source 110 is provided for shading and illumination. During rendering, each 3D fragment of the 3D objects is projected onto the near plane 106, resulting in a two-dimensional (2D) image that can be displayed on a computer monitor.
For realistic image rendering, the 3D objects 104 are analyzed for shading and illumination with respect to the light source 110. Specifically, pixels that are occluded from the light source 110 generally are given darker pixel shadings than pixels not occluded from the light source 110. Thus, “shadows” are created based on each object's position with respect to other objects and the light source 110. Currently, developers utilize several techniques to determine shading in 3D rendering. Two such techniques are shadow volumes and shadow texturing. Additional information on shadow volumes and shadow texturing can be found in Crow, F. C., Shadow Algorithms for Computer Graphics, Computer Graphics, 11(3), 242-8, (Proc. SIGGRAPH '77), and Williams, L., Casting Curved Shadows on Curved Surfaces. Computer Graphics, 12(3), 270-4, (Proc. SIGGRAPH '78), which are each incorporated herein by reference.
FIG. 2 is an illustration showing a conventional shadow volume space 200 utilized for shading during 3D rendering. A shadow volume space 200 is generated based on a light source 110 and an occluding polygon 202. In particular, the shadow volume space 200 is generated by forming a volume from the light source 110 through the vertices of the occluding polygon 202, such that the projection of the edges of the occluding polygon 202 constrain the shadow volume space 200. Thereafter, when rendering other objects, such as polygon 204, pixels inside the shadow volume space 200 are shaded by the occluding polygon 202, and pixels outside the shadow volume space 200 are not shaded by the occluding polygon 202.
Unfortunately, the construction of each shadow volume space 200 is performed by the central processing unit (CPU) of a computer. Hence, the computing intensity on the CPU increases as the number of edges an object has increases. As a result, objects having many curves, and thus many edges, increase the amount of CPU processing time needed for rendering. Although curved objects are often described using few vertex points that are later interpolated to create the curve, each interpolated edge requires CPU processing to create the shadow volume space 200 for that object. To avoid problems resulting from shadow volumes, many developers utilize shadow texturing for shading.
As is well known in the prior art, modeling is the transformation from object coordinates to world coordinates. To account for the camera's view of the 3D objects within the world coordinate system, a viewing transformation is applied. A projection transformation maps points within a view frustum to a normalized viewing volume and a viewport transformation maps (x,y) coordinates from within the normalized viewing volume to the screen coordinates of the viewport. Further information regarding computer 3D modeling can be found in Computer Graphics Principles and Practices by Foley, et al., which is incorporated by reference. This cited reference contains background on other relevant terms such as modeling, viewing, projection, and viewport transformations as well as viewing, projection, and viewport transformations along with scan conversion, depth-testing, pixel shading, texturing, (and conventional cube mapping).
FIG. 3 is an illustration showing a 3D viewing space 300 based on shadow texturing. As above, the 3D objects, here a sphere 306 on a plane 308, are rendered from the camera's 102 point of view, generally between a near plane 106 and a far plane 108, with a light source 110 for shading and illumination. During rendering, each 3D fragment of the 3D objects is projected onto the near plane 106, resulting in a two-dimensional (2D) image that can be displayed on a computer monitor.
Before rendering from the camera's view 102, the 3D objects 306 and 308 are rendered from the perspective of the light source 110 using a depth buffer 302. In particular, the depth buffer 302 is located at the near plane for the light source 110. The light source also has a far plane 304, similar to the camera's far plane 108. To create the depth buffer 302, a range is measured from each pixel on the 3D objects 306 and 308 to the light source 110. This range is then recorded at a projected position within the depth buffer 302. If a subsequent range is determined for the same location within the depth buffer, the range closest to light source is recorded. For example, pixel 306′ of the sphere 306 is projected on the near plane of the light source 110 at location 306″. The range between the pixel 306′ and the light source 110 is then recorded at location 306″ in the depth buffer 302. A similar operation is performed for pixel 308′ of the plane 308, which is projected on the near plane of the light source 110 at location 308″. The depth buffer 302 thereafter is copied to a shadow texture, as described next with reference to FIG. 4.
FIG. 4 is a diagram showing an exemplary shadow texture 400 for a light source. The shadow texture 400 corresponds to the depth buffer 302 of FIG. 3, and includes a plurality of range values corresponding to pixel ranges to the light source. Hence, the shadow texture 400 locations corresponding to the sphere 306″ have values nearer to the light source 110 than shadow texture 400 locations corresponding to the plane 308″.
Referring back to FIG. 3, the 3D objects 306 and 308 are then rendered from the camera's perspective and shaded using the shadow texture 400. In particular, each object 306 and 308 initially is rendered assuming no occlusion from the light source. Thereafter, each pixel is examined to determine shading. Specifically, for each object surface pixel, the range from the light source 110 to the pixel is determined. In addition, the object pixel is projected onto the near plane of the light source 110, thus transforming its location from a 3D point to a 2D point within the depth buffer 302. The 2D coordinates of the projected point then are used to index into the shadow texture 400 to obtain the stored range value. If the range value from the shadow texture 400 is closer to the light source than the range from the current object surface pixel, the current object surface pixel is shaded. Otherwise, no occluding objects are located between the current object surface pixel and the light source and the object surface pixel is not shaded.
Although shadow texturing works well for light sources that are essentially spotlights that cast shadows in one direction, conventional shadow texturing generally does not work well for omnidirectional light sources, which may cast shadows in all directions. To do so requires a plurality of shadow texture lookups for each pixel rendered, resulting in greatly increased processor time and reduced performance. That is, a shadow texture would be required for each direction from the light source, and all the shadow textures would need to be examined for each pixel rendered. In current processors, such a multi-texture lookup is unworkable in a real-time environment.
As is well known in the prior art, Cube Texture Mapping provides a mechanism for omnidirectional reflection mapping wherein a three dimensional texture coordinate (representing a reflection vector) is transformed into a Cube Face Identifier (selecting one of six cube face two dimensional texture maps) and a two dimensional texture coordinate (selecting a particular texel within the selected two dimensional texture map) though Cube Texture Mapping can accept any 3D vector as texture coordinate input (including a light to surface vector) the practice as known in the state of the art collapses the 3D vector into a 2D vector and a face identifier—thereby losing the necessary depth information to perform shadow texturing. Additional information on Cube Texture Mapping can be found in Greene, N., Environment Mapping and Other Applications of World Projections, IEEE Computer Graphics and Applications, 6(11), 21-9, November 1986, which is incorporated herein by reference.
In view of the foregoing, there is a need for systems and methods for omnidirectional shadow texture mapping in real-time systems. The methods should provide omnidirectional shadow texture mapping without requiring multiple texture lookups or greatly increased CPU processing time for objects having a large number of edges, such as curved objects.